package testing.manager;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.util.Properties;
import java.util.Random;

//import utilities.display.DrawShape;
import utilities.display.shapes.definedshapes.DrawRectangle;
//import utilities.display.iface.Drawable;
import utilities.manager.Runner;

/**
 * 
 * @author CoconutTank
 *
 */
public class FlashingRectangleRunner extends Runner
{
	/**
	 * 
	 */
	private static final long serialVersionUID = -1712076549823158366L;

	private DrawRectangle whatCouldThisBe = null;
	//private DrawRectangle whatCouldThisBe = null;
	//private ShapedGraphic whatCouldThisBe = null;
	//private Drawable whatCouldThisBe = null;
	private int dx = 5;
	private int dy = 0;
	private Random rand = new Random();

	public FlashingRectangleRunner(int width, int height, Color backgroundColor) 
	{
		super(width, height, backgroundColor);
		whatCouldThisBe = new DrawRectangle(0, 0, 100, 70, Color.black, new BasicStroke(2), null, Color.white, null);
	}

	public void gameUpdate(Properties runnerVars) 
	{
		// Keep rectangle within the screen!
		//if(whatCouldThisBe.x + whatCouldThisBe.width + dx >= this.getWidth() && dy <= 0)
		if(whatCouldThisBe.getShape().x + whatCouldThisBe.getShape().y + dx >= this.getWidth() && dy <= 0)
		{
			dx = -5;
		}
		//else if(whatCouldThisBe.x + dx <= 0)
		else if(whatCouldThisBe.getShape().x + dx <= 0)
		{
			dx = 5;
		}
		
		// Move rectangle
		//whatCouldThisBe.x += dx;
		//whatCouldThisBe.y += dy;
		whatCouldThisBe.getShape().translate(dx, dy);
	}

	public void drawScreen(Graphics g) 
	{
		// Type cast
		Graphics2D g2 = (Graphics2D) g;
		
		// Get original settings...
		Color c = g2.getColor();
		
		// Draw background
		drawBackgroundColor(g2);
		
		// Draw spazzy rectangle
		drawContent(g2);
		
		// Return original settings...
		g2.setColor(c);
	}

	/**
	 * 
	 * @param g2
	 */
	public void drawContent(Graphics2D g2) {
		if(whatCouldThisBe != null)
		{
			whatCouldThisBe.drawMe(g2);
			whatCouldThisBe.setFillColor(new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256)));
		}
	}

	/**
	 * 
	 * @param g2
	 */
	public void drawBackgroundColor(Graphics2D g2)
	{
		g2.setColor(this.getBackground());
		g2.fillRect(0, 0, this.getWidth(), this.getHeight());
	}
}
